package exmpcase;

import java.util.ArrayList;
import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        //创建一个集合添加整数
        ArrayList<Integer> list = new ArrayList<>();

        while (true){
            System.out.println("请输入一个数字");
            int num = new Scanner(System.in).nextInt();
            if (num <1 || num >100){
                System.out.println("请输入1-100之间的数字");
                continue;
            }
            list.add(num);
            if (!isOverSize(list,100)){
                System.out.println("集合已满");
                break;
            }
        }
    }
    public static boolean isOverSize(ArrayList<Integer> list,Integer max){
        Integer sum = 0;
        for (Integer integer : list) {
            sum += integer;
        }
        return sum<=max;
    }
}
